package com.jcy.common.configuration;

import net.sf.ehcache.CacheManager;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;

/**
 * @Description:
 * @Auther: jcy
 * @Date: 2021/7/1 11:03
 */
public class EhcacheConfig {
    @Bean
    @ConditionalOnMissingBean(CacheManager.class)
    @ConditionalOnClass(CacheManager.class)
    public CacheManager cacheManager() throws IOException {
        ClassPathResource resource = new ClassPathResource("ehcache.xml");
        CacheManager cacheManager = new CacheManager(resource.getInputStream());
        return cacheManager;
    }
}
